package com.vlms.demo;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.TemplateConfig;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.junit.Test;

import java.util.Collections;

/**
 * 代码生成器
 *
 * @author wangchunhui
 * @date 2023/2/16 15:09
 */
public class Generator {

    @Test
    public void run() {
        String url = "jdbc:mysql://10.118.9.50:3306/vlcp?serverTimezone=GMT%2B8";
        String username = "hzyf";
        String password = "hzyf@2022";
        String parentPackage = "com.weixin.common";
        String moduleName = "manage";
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author("wangchunhui") // 设置作者
                            .fileOverride() // 覆盖已生成文件
                            .commentDate("yyyy-MM-dd")
                            .outputDir("D:\\codeInstances\\springboot-test2022.1.24\\ch_common\\src\\main\\java\\"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent(parentPackage) // 设置父包名
                            .moduleName(moduleName)
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D:\\codeInstances\\springboot-test2022.1.24\\ch_engine\\src\\main\\resources\\mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("bs_compensate_file")// 设置需要生成的表名
//                  builder.addInclude("xxx", "xxx")
                            .addTablePrefix("bs_"); // 设置过滤表前缀
                })
                .strategyConfig(builder -> {
                    builder.mapperBuilder()
                            //生成resultMap
                            .enableBaseResultMap()
                            //生成基础查询列
                            .enableBaseColumnList()
                            .entityBuilder()
                            //生成lombok
                            .enableLombok();
//                            .controllerBuilder()
                    //实现baseController
                    //restful风格
//                            .enableRestStyle();
                    //使用freemarker
                }).templateEngine(new FreemarkerTemplateEngine())
                .execute();


    }
}
